﻿@model billtracker.Models.bill
@using (Html.BeginForm())
{
 <div class="modal-header">
              <a class="close" data-dismiss="modal" onclick="hideMe();">×</a>
              <h3><i class="icon-trash icon-black"></i> Delete Bill</h3>
            </div>
     <div class="modal-body">
     @Html.HiddenFor(model => model.billId)
     @Html.HiddenFor(model => model.name)
     Are your sure you want to delete the bill <strong>@Html.DisplayFor(model => model.name)</strong>?

     

     </div> 
     }
     <div class="modal-footer">
              <input id="save" type="submit" value="Delete Bill" onclick="doPost();" class="btn btn-primary" />
            <input type="submit" value="Cancel" onclick="hideMe();" class="btn"  />
            </div> 
<script type="text/javascript">
    var currentBillName = "";
    function doPost() {

       var url = '@Url.Action("DeleteBill", "Bills")';
        $.post(url, $('form').serialize(), function (data) {
            if (data == false) {
                //INVALID FORM OR ERROR
            }
            else {
                currentBillName = $('#name').val();
                reloadmain();
                hideMe();
            }

            // alert("Data Loaded: " + data);
            //reloadmain();

        })
        //    hideMe();
    }
    function hideMe() {
        //    $("#popUp").hide("slow");

        $("#popUp").hide("fast");
        $("#backdrop").remove();
        // alert($(this).serialize());
    }
    function reloadmain() {
        var url = '@Url.Action("Index", "Bills")' + "?rnd=" + rand();
        $.get(url, function (data) {
            $('#page').html(data);
            //  $("#info").append("<span><i class='icon-info-sign icon-white'></i> Bill Saved</span>");
            $("#info").append("<div class='alert alert-success'><a class='close' data-dismiss='alert'>×</a>Bill <string>" + currentBillName + "</strong> has been successfully deleted!</div>");
            $("#info").slideDown('slow');
            $("#info").delay(5000).slideToggle('slow');
        });


    }
</script>
